<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>会员产品</title> $!{include("import_js_css.html")}
<!--#var(Member member)-->
</head>
<script type="text/javascript">
$(function(){
	var buyAtSameTime = "${buyAtSameTime}";
	if(buyAtSameTime){
		$("#selectProductAllButton").hide();
		$("#selectProduct").css("display", "block");
		$("#selectProduct #product_all_table :checkbox").prop("checked",false);
		$("#selectProduct2").css("display", "block");
	}
	
	$("#checkOrder").click(function(){
		window.location.href = "yueyogaAdmin/searchProducts.jhtml?index=consumeList&memberId=${member.memberid}";
	});
	
	$("#spMemberRemaining").text("${member.remaining.remaining}");
});
</script>
<body>
	$!{include("header.html")}
	<div class="container menu_all">
		<div class="panel panel-info">
			
			$!{include("memberHeader.html")}
			<div id="div_result_member" style="padding: 15px;">
				<div class="panel">
					$!{include("member_info_tab.html")}
					<div class="panel-hxcd-info">
						<input type="hidden" id="hidMemberId" value="${member.memberid}" />
						<div class="panel-heading panel-result-title">
							<h3 class="panel-title">购买的产品</h3>
							<div class="btn-group btn-gp-default">
								<button id="selectProductAllButton" type="button"
										class="btn btn-default panel-radius-left">购买产品</button>
								<button id="renewals" type="button"
										class="btn btn-default panel-radius-right">会员续费</button>
								</div>
						</div>
						<div>$!{include("member_product_list.html")}</div>
						<form name="memberProductForm" action="yueyogaAdmin/toMemberProduct.jhtml">
							<input name="memberId" value="${member.memberid}" type="hidden"> <input type="hidden" name="pagePNo" id="hidPPageNo"> <input type="hidden" name="pagePRNo" id="hidPRPageNo"> <input type="hidden" name="pageNo" id="hidPageNo"> <input type="hidden"
								name="pageProONo" id="hidPageProONo">
						</form>
						
						<!-- 会员购买产品订单 -->
						<div class="div_search_result clear">
							<div class="panel-heading panel-result-title">
								<h3 class="panel-title">下单记录</h3>
								<div class="btn-group btn-gp-default">
									<button id="disableOrderTint" type="button"	class="btn btn-default panel-radius-left">会员退款</button>
									<button id="clearOrder" type="button" class="btn btn-default panel-radius-none">定金结清</button>
									<button id="checkOrderDetail" type="button" class="btn btn-default panel-radius-none">查看详情</button>
									<button id="exportContract" type="button"
										class="btn btn-default panel-radius-none">导出合同</button>
								<button id="printContract" type="button"
										class="btn btn-default panel-radius-right">打印合同</button>
								</div>
							</div>
							<div>$!{include("member_prorder_list.html")}</div>
						</div>
						
					<div class="panel">
					<div class="panel-heading panel-result-title">
						<h3 class="panel-title">使用情况</h3>
						<div class="btn-group btn-gp-default">
							<button id="checkOrder" type="button" class="btn btn-default panel-radius-left">消费记录</button>
							<button id="changeRestTimes" type="button" class="btn btn-default panel-radius-none">更改剩余次数</button>
							<button id="grantTime" type="button" class="btn btn-default panel-radius-none">更改有效期</button>
							<button id="delayProductValidDays" type="button" class="btn btn-default panel-radius-right">产品延期</button>
						</div>
					</div>
					<div>$!{include("member_productremaining_list.html")}</div>
				</div>	
					</div>
				</div>
			</div>
		</div>
	</div>

	<div id="selectProduct2" style="display: none; position: absolute; left: 0; top: 0; width: 100%; height: 180%; background-color: black; filter: alpha(opacity = 70); -moz-opacity: 0.7; opacity: 0.7;"></div>

	<div id="selectProduct" style="display: none; width: 100%; position: fixed; left: 0; top: 15%; margin: auto;">
		<div id="selectProductCloseButton" style="position: absolute; right: 210px; top: 10px; width: 20px; height: 20px; text-align: center; font-size: 14px; cursor: pointer;" title="关闭">×</div>
		<div class="panel panel-info" style="margin-left: 200px; margin-right: 200px; z-index: 2;">
			<div class="panel-heading panel-result-title">
				<h3 class="panel-title">所有产品</h3>
			</div>
			<div class="div_search_result clear">$!{include("product_member_all_list.html")}</div>
		</div>
	</div>
	
	<div id="buyProductsDetails" class="panel-dialog-gzjl panel-radius-all" style="top: 115%; display: none; z-index: 10;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">产品购买</h3>
		</div>
		<br />
		<div style="margin: 0 33px 0 50px;">
			<label for="selPerson" class="col-sm-1 control-label">负责人</label>
			<div class="col-sm-8">
				<select id="input" class="selectpicker" data-width="100%" name="seller" style="z-index: 10000;">
					<!-- #for(GroupUserModel respor : responsibleList) -->
					<option value="${respor.id}">${respor.name}</option>
					<!-- #end -->
				</select>
			</div>
			<br /> <br /> 
			<label for="txtTestName" class="col-sm-1 control-label">购买类型</label>
			<div class="col-sm-8">
				<select id="buyType" class="selectpicker show-tick" data-width="100%" name="buyType">
					<option value=""> </option>
					<option value="新销售" selected>新销售</option>
					<option value="定金">定金</option>
				</select>
			</div>
			<br /> <br /> <label for="amounts" class="col-sm-1 control-label">总金额</label>
			<div class="col-sm-8">
				<input type="text" class="form-control panel-text-bg" readonly id="amounts" />
			</div>
			
			<div id="qsjs_date">
				<br> <br>
				<label for="txtBeginDate"
					class="clear col-sm-1 control-label">开始日期</label>
				<div class="col-sm-8">
	                <div class='input-group date'  style="padding-left: -15px !important;" id='txtBeginDate' data-date-format="YYYY-MM-DD">
	                    <input name="qzBeginDate" id="qzBeginDate" type='text' class="form-control"/>
	                    <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
	                    </span>
	                </div>
				</div>
				<br> <br>
				<label for="txtEndDate" class="clear col-sm-1 control-label">结束日期</label>
				<div class="col-sm-8">
	                <div class='input-group date' id='txtEndDate' data-date-format="YYYY-MM-DD">
	                    <input name="qzEndDate" id="qzEndDate" type='text' class="form-control" />
	                    <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
	                    </span>
	                </div>
				</div>
			</div>
			
			<div id="earnests" style="display: none;">
				<br> <br>
				<label for="earnest" class="clear col-sm-1 control-label">定金</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="earnest" />
				</div>
			</div>
			
			<div class="panel-btn-search" style="text-align: right; margin-right: 60px;margin-top:80px;">
				<button id="btn_buy_product" onclick="buyProducts()" type="button" class="btn btn-default btn-ade-default">购买</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="btn_close" onclick="toggleDiv()" class="btn btn-default btn-ade-default" style="margin-right: 20px;">取消</button>
			</div>
		</div>
	</div>
	
	<!-- 退费 -->
	<div id="disableOrderPanel" class="panel-dialog-gzjl panel-radius-all" style="top: 115%; display: none; z-index: 10;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">退费</h3>
		</div>
		<br />
		<div style="margin: 0 33px 0 50px;">
			<label for="disableCharger" class="col-sm-1 control-label">负责人</label>
			<div class="col-sm-8">
				<select id="disableCharger" data-live-search="true" class="selectpicker show-tick" data-width="100%" name="seller" style="z-index: 10000;">
					<option value=""> </option>
					<!-- #for(GroupUserModel respor : responsibleList) -->
						<option value="${respor.id}">${respor.name}</option>
					<!-- #end -->
				</select>
			</div>
			<br /> <br />
			
			<div class="panel-btn-search" style="text-align: right; margin-right: 60px;margin-top:80px;">
				<button id="disableOrder" type="button" class="btn btn-default btn-ade-default">退费</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="diableOrderCancelButton" class="btn btn-default btn-ade-default" style="margin-right: 20px;">取消</button>
			</div>
		</div>
	</div>
	
	<!-- 产品延期 -->
	<div id="delayProductValidDaysDiv" class="panel-dialog-gzjl panel-radius-all" style="top: 115%; display: none; z-index: 10;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">产品延期</h3>
		</div>
		<br />
		<div style="margin: 0 40px;">
			<label for="iptDelayProductDays" class="col-sm-1 control-label label-pro-chose">延期天数</label>
			<input id="iptDelayProductDays" type="text" style="height:35px;line-height:35px;">
			<br> <br>
			<div class="panel-btn-search" style="text-align: right; margin-right: 60px;">
				<button type="button" id="btn_delaydays_close" class="btn btn-default btn-ade-default" >取消</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="btn_delaydays_save" class="btn btn-default btn-ade-default" style="margin-right: 20px;">保存</button>
			</div>
		</div>
	</div>
	<!-- 产品延期 -->
	
	<!-- 更改剩余次数 -->
	<div id="changeRestTimeDiv" class="panel-dialog-gzjl panel-radius-all" style="top: 115%; display: none; z-index: 10;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">产品剩余次数</h3>
		</div>
		<br />
		<div style="margin: 0 40px;">
			<label for="inputRestTimes" class="col-sm-1 control-label label-pro-chose">剩余次数</label>
			<input id="inputRestTimes" type="text" style="height:35px;line-height:35px;">
			<br> <br>
			<div class="panel-btn-search" style="text-align: right; margin-right: 60px;">
				<button type="button" id="btn_changeresttimes_close" class="btn btn-default btn-ade-default" >取消</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="btn_changeresttime_save" class="btn btn-default btn-ade-default" style="margin-right: 20px;">保存</button>
			</div>
		</div>
	</div>
	<!-- 更改剩余次数 -->
	
	<div id="buyProductTime" class="panel-dialog-gzjl panel-radius-all" style="top: 115%; display: none; z-index: 10;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">产品有效时间</h3>
		</div>
		<br />
		<form action="yueyogaAdmin/updateProRemainingTime.jhtml" name="proTimeForm" method="post">
		<input type="hidden" id="checkedProductRemainingIds" name="proRemainIds"/>
		<div style="margin: 0 40px;">
			<label for="selPerson" class="col-sm-1 control-label label-pro-chose">开始时间</label>
			<div class="col-sm-8">
				<div class='input-group date' id='proBeginTime' data-date-format="YYYY-MM-DD">
			    <input name="proBeginTime" type="text" required class="form-control" style="background-color:#fff;" />
			    <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
			     </span>
			    </div>
			</div>
			<br/><br/><br/>
			<label for="txtTestName" class="col-sm-1 control-label label-pro-chose">结束时间</label>
			<div class="col-sm-8">
				<div class='input-group date' id='proEndTime' data-date-format="YYYY-MM-DD">
			    <input name="proEndTime" type="text" required class="form-control" style="background-color:#fff;" />
			    <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
			     </span>
			    </div>
			</div>
			<br> <br><br/>
			<div id="divFzr" style="display: none;">
			<label for="selPerson" class="col-sm-1 control-label label-pro-chose">负责人</label>
			<div class="col-sm-8">
				<select id="selFzrs" data-live-search="true" class="selectpicker" data-width="100%" name="seller">
					<option value="">请选择负责人</option>
					<!-- #for(GroupUserModel respor : responsibleList) -->
					<option value="${respor.id}">${respor.name}</option>
					<!-- #end -->
				</select>
			</div>
			</div>
			<br> <br>
			<div class="panel-btn-search" style="text-align: right; margin-right: 60px;">
				<button type="button" id="btn_close" onclick="toggleTimeDiv()" class="btn btn-default btn-ade-default" >取消</button>
				&nbsp;&nbsp;&nbsp;
				<button id="btnGrantTime" name="btnSave" type="button" onclick="grantProductTime()" class="btn btn-default btn-ade-default" style="margin-right: 20px;">保存</button>
			</div>
		</div>
		</form>
	</div>
	
	<!-- 定金输入折扣 -->
	<div id="clearOrderDiscount" class="panel-dialog-gzjl panel-radius-all" style="top: 115%; display: none; z-index: 10;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">产品折扣</h3>
		</div>
		<br />
		<form action="yueyogaAdmin/updateProRemainingTime.jhtml" name="clearOrderDiscountForm" method="post">
		<input type="hidden" id="hidProRemainIds" name="proRemainIds"/>
		<div style="margin: 0 40px;">
			<label for="amounts" class="col-sm-1 control-label label-pro-chose">折扣</label>
			<div class="col-sm-8">
				<input type="text" class="form-control panel-text-bg" id="clearOrderDiscountPrice" />
			</div>
			<br><br>
			<br><br>
			<label for="clearCharger" class="col-sm-1 control-label label-pro-chose">负责人</label>
			<div class="col-sm-8">
				<select id="clearCharger" data-live-search="true" class="selectpicker show-tick" data-width="100%" name="seller" style="width: 200px; z-index: 10000;">
					<option value=""> </option>
					<!-- #for(GroupUserModel respor : responsibleList) -->
						<option value="${respor.id}">${respor.name}</option>
					<!-- #end -->
				</select>
			</div>
			<br /> <br />
			<br><br>
			<div class="panel-btn-search" style="text-align: right; margin-right: 60px;">
				<button id="clearOrderDiscountBuyButton" type="button" class="btn btn-default btn-ade-default">结清</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="clearOrderDiscountCancelButton" class="btn btn-default btn-ade-default" style="margin-right: 20px;">取消</button>
			</div>
		</div>
		</form>
	</div>
	
	<!-- 产品退款 -->
	<div id="refundProducts" class="panel-dialog-gzjl panel-radius-all" style="top: 115%; display: none;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">产品退款</h3>
		</div>
		<br />
		<div style="margin: 0 40px;">
			<br/>
			<label for="txtTestName" class="col-sm-1 control-label label-pro-chose">退款金额</label>
			<div class="col-sm-8">
			    <input name="refundMoney" id="refundMoney" type="text" required class="form-control" style="background-color:#fff;" />
			 </div>
			<br> <br><br/>
			<label for="selPerson" class="col-sm-1 control-label label-pro-chose">负责人</label>
			<div class="col-sm-8">
				<select id="selTkFzrs" data-live-search="true" class="selectpicker" data-width="100%" name="seller">
					<option value="">请选择负责人</option>
					<!-- #for(GroupUserModel respor : responsibleList) -->
					<option value="${respor.id}">${respor.name}</option>
					<!-- #end -->
				</select>
			</div>
			<br> <br>
			<div class="panel-btn-search" style="text-align: right; margin-right: 60px;">
				<button id="btnRefund" name="btnSave" type="button" class="btn btn-default btn-ade-default">保存</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="btn_close" onclick="toggleRefundDiv()" class="btn btn-default btn-ade-default" style="margin-right: 20px;">取消</button>
			</div>
		</div>
	</div>
	
	
	<!-- 显示订单详情 -->
	<div id="selectProductOrderDetailBackground" style="display: none; position: absolute; left: 0; top: 0; width: 100%; height: 180%; background-color: black; filter: alpha(opacity = 70); -moz-opacity: 0.7; opacity: 0.7; z-index: 10000;"></div>
	<div id="selectOrderDetail" style="display: none; width: 100%; position: fixed; left: 0; top: 15%; margin: auto; z-index: 10000;">
		<div id="selectOrderDetailCloseButton" style="position: absolute; right: 210px; top: 10px; width: 20px; height: 20px; text-align: center; font-size: 14px; cursor: pointer;" title="关闭">×</div>
		<div class="panel panel-info" style="margin-left: 200px; margin-right: 200px; z-index: 2;">
			<div class="panel-heading panel-result-title">
				<h3 class="panel-title">订单详情</h3>
			</div>
			<div class="div_search_result clear">$!{include("member_order_detail_list.html")}</div>
		</div>
	</div>
	
	<form id="exportContractForm" action="yueyogaAdmin/exportContractPdf.jhtml" method="post" style="display:none;" target="_blank">
		<input id="order" name="orderId" type="hidden" />
	</form>
	
	<script type="text/javascript">
    $(document).ready(function(){
    	$("#earnest").keyup(function(){
			var comment = $("#earnest").val();
			if(comment == 0){
				$("#earnest").val("");
				$("#buyProductsDetails").hide();
			    alert("定金不能为0");
				
			}
		});
    	
    	//点击打开会员退款提示
    	$("#disableOrderTint").click(function() {
    		$("#disableOrderPanel").css("display", "block");
    	});
    	
    	//点击取消关闭退款提示
    	$("#diableOrderCancelButton").click(function() {
    		$("#disableOrderPanel").css("display", "none");
    	});
    });
	$(".date").datetimepicker({
		format : "YYYY-MM-DD",
		language : "zh-CN",
		pickTime : false
	});
	$("#selTkFzrs").val('${resporsId}');
	$("#proBeginTime").on("dp.change", function(e) {
		$("#proEndTime").data("DateTimePicker").setMinDate(e.date);
	});

	$("#proEndTime").on("dp.change", function(e) {
		$("#proBeginTime").data("DateTimePicker").setMaxDate(e.date);
	});
	
	
	$("#txtBeginDate").on("dp.change", function(e) {
		$("#txtEndDate").data("DateTimePicker").setMinDate(e.date);
	});

	$("#txtEndDate").on("dp.change", function(e) {
		$("#txtBeginDate").data("DateTimePicker").setMaxDate(e.date);
	});
	function documentReady() {
		//弹出延期div
		$("#delayProductValidDays").click(function(){
			var checked = $(":input[name=proremaining_item]:checked");
			if(checked.length == 0){
				alert("请选择您要对产品延期的行");
				return;
			}
			$("#delayProductValidDaysDiv").show();
		});
		
		
		$("#btn_delaydays_close").click(function(){
			$("#delayProductValidDaysDiv").hide();
		});
		
		$("#btn_delaydays_save").click(function(){
			var delayDays = $("#iptDelayProductDays").val();
			var intDelayDays = parseInt(delayDays);
			
			if(delayDays == "" || isNaN(intDelayDays)){
				alert("请填写延期天数（正整数）");
				return;
			}
		
			var checkedItems = $(":input[name=proremaining_item]:checked");
			var ids = "";
			checkedItems.each(function(idx,item){
				ids += $(this).parents("tr").attr("data") + ",";
			});
			
			var url = "yueyogaAdmin/updateProRemainingEndTime.jhtml";
			$.post(url,{
				ids:ids,
				count:intDelayDays
			},function(resp){
				var json = eval("("+resp+")");
				$("#delayProductValidDaysDiv").hide();
				
				if(json.success){
					window.location.reload();
				}else {
					alert("产品延期操作失败");
				}
			});
		});
		
		
		//弹出更改剩余次数div
		$("#changeRestTimes").click(function(){
			var checked = $(":input[name=proremaining_item]:checked");
			if(checked.length == 0){
				alert("请选择您要更改的行");
				return;
			}
			$("#changeRestTimeDiv").show();
		});
		
		//关闭更改剩余次数div
		$("#btn_changeresttimes_close").click(function(){
			$("#changeRestTimeDiv").hide();
		});
		
		//确认更改剩余次数
		$("#btn_changeresttime_save").click(function(){
			var restTimes = $("#inputRestTimes").val();
			if(restTimes==""){
				alert("请填写剩余次数（整数）");
			}
			if(isNaN(restTimes)){
				alert("必须输入数字");
				return;
			}
			
			var intRestTimes = parseInt(restTimes);
			var checkedItems = $(":input[name=proremaining_item]:checked");
			var ids = "";
			checkedItems.each(function(idx,item){
				ids += $(this).parents("tr").attr("data") + ",";
			});
			
			var url = "yueyogaAdmin/updateProRemainingRestTimes.jhtml";
			$.post(url,{
				ids:ids,
				count:intRestTimes
			},function(resp){
				var json = eval("("+resp+")");
				$("#changeRestTimeDiv").hide();
				
				if(json.success){
					var idArray = ids.split(",");
					if(idArray && idArray.length>0){
						$.each(idArray,function(idx,item){
							if(item){
								$("#restTimes_"+item).text(intRestTimes);
							}
						});
					}
				}else {
					alert("更改产品次数失败");
				}
			});
		});

		
			//点击显示所有产品，选择需要购买的产品
			$("#selectProductAllButton").click(function() {
				$(this).hide();
				$("#selectProduct").css("display", "block");
				//去除所有复选
				$("#selectProduct #product_all_table :checkbox").prop("checked",false);
				$("#selectProduct2").css("display", "block");
			});
			
			//去掉下拉输入框
			$("#buyType").select2({
				width: "100%",
				minimumResultsForSearch: -1
			});
			
			$("input[name='proRemainingId']").click(function(){
				
			});
			//购买产品
			//关闭选择产品页面
			$("#selectProductCloseButton").click(function() {
				$("#selectProductAllButton").show();
				$("#selectProduct").css("display", "none");
				$("#selectProduct2").css("display", "none");
				$("#earnest").val("");
			});
			
			$("#buyType").change(function() {
				if ($(this).val() == '定金') {
					$("#earnests").show();
					$("#qsjs_date").hide();
					$("#qzBeginDate").val("");
					$("#qzEndDate").val("");
				} else {
					$("#earnests").hide();
					$("#qsjs_date").show();
					$("#earnest").val("");
				}
			});
			
			//--指定产品的使用时间
			$("#grantTime").click(function(){
				var ids = [];
				$(':input[name="proremaining_item"]:checked').each(function() {
					ids.push($(this).parents("tr").attr("data"));
				});
				if(ids.length > 0){
					$("#checkedProductRemainingIds").val(ids);
					ids = [];
					toggleTimeDiv();
				}else{
					alert("请选择至少一条记录!");
					return;
				}
			});
			
			$("#chx_proRemainingIds").click(function(){
				$('input[name="proRemainingId"]').prop('checked',$(this).prop('checked'));
			});
			
			//--续费----------------------------------------
			$("#renewals").click(function(){
				var ids = [];
				$('input[name="proRemainingId"]:checked').each(function() {
					ids.push($(this).val());
				});
				if(ids.length > 0){
					$("#buyProductTime h3").text("产品续费");
					$("button[name='btnSave']").prop("id","renewalProduct");
					$("#hidProRemainIds").val(ids);
					$("#divFzr").show();
					$("#buyProductTime").slideToggle("fast");
				}else{
					alert("请选择至少一条记录!");
					return;
				}
				ids = [];
			});
			
			//--弹出退款
			$("#refund").click(function(){
				var ids = [];
				$('input[name="proRemainingId"]:checked').each(function() {
					ids.push($(this).val());
				});
				if(ids.length > 0){
					$("#hidProRemainIds").val(ids);
					toggleRefundDiv();
				}else{
					alert("请选择至少一条记录!");
					return;
				}
			});
			
			//--退款
			$("#btnRefund").click(function(){
				var memberId = $("#hidMemberId").val();
				var sellerId = $("#selTkFzrs").val();
				var refundMoney = $("#refundMoney").val();
				toggleRefundDiv();
				if(!refundMoney){
					var d = alert("请输入退款金额!");
					setTimeout(function(){
						d.close().remove();
					},1000);
					return;
				}
				if(!sellerId){
					var d = alert("请选择负责人!");
					setTimeout(function(){
						d.close().remove();
					},1000);
					return;
				}
				var proRemainIds = $("#hidProRemainIds").val();
				var url = "yueyogaAdmin/refundProducts.jhtml";
				$.post(url,
					{proRemainIds:proRemainIds,
					 memberId:memberId,
					 sellerId:sellerId,
					 refundMoney:refundMoney
					},function(data){
						var resp = eval('('+data+')');
						if(resp.success){
							window.location.reload();
						}else{
							error(resp.msg);
						}
					});
				$('input[name="proRemainingId"]').prop('checked',false);
			});
			
			//查看订单详情
			$("#checkOrderDetail").click(function() {
				
				var count = $("input[name^='prorder_']:checked").length;
				if (count <= 0) {
					error("请选择一个订单！")
					return;
				} else if (count > 1) {
					error("只能选择一个订单！")
					return;
				}
				
				var orderId = "";
				var name = $("input[name^='prorder_']:checked").attr("name");
				orderId = name.substring(8, name.length);
				$.ajax({
					type		: "post",
					url 		: "yueyogaAdmin/findOrderDetailByOrderId.jhtml",
					async		: false,
					data		: {"orderId": orderId, "start": 0, "limit": 5},
					success		: function(response) {
						$("#order_detail_table").html("<tr><td>产品名称</td><td>产品类型</td><td>产品价格(元)</td></tr>");
						var res = eval("(" + response + ")");
						if (res.success) {
							for (var i = 0;i < res.total;i ++) {
								$("#order_detail_table").append("<tr><td>" + res.items[i].productName + "</td><td>" + res.items[i].productType + "</td><td>" + res.items[i].productPrice + "</td></tr>");
							}
							
							var pages = res.totalPages * 1;
							if (pages > 1) {
								$("#order_detail_prePage").addClass("disabled");
								$("#order_detail_nextPage").removeClass("disabled");
							} else {
								$("#order_detail_prePage").addClass("disabled");
								$("#order_detail_nextPage").addClass("disabled");
							}
							
							$("#txtODPageNumber").val(1);
							$("#pageODNo").val(1);
							$("#pageODTotalPages").val(pages);
							//显示共几页
							$("#span_totalODPages").text(pages);
							//显示共几条数据
							$("#span_totalODResults").text(res.totalResults);
						} else {
							error(res.msg);
						}
					}
				});
				
				$("#selectProductOrderDetailBackground").css("display", "block");
				$("#selectOrderDetail").css("display", "block");
			});
			
			
			//导出合同套打模板
			$("#exportContract").click(function(){
				var count = $("input[name^='prorder_']:checked").length;
				if (count <= 0) {
					error("请选择一个订单进行打印")
					return;
				} else if (count > 1) {
					error("一次仅能选择一个订单")
					return;
				}
				var orderId = "";
				var name = $("input[name^='prorder_']:checked").attr("name");
				orderId = name.substring(8, name.length);

				$("#exportContractForm #order").val(orderId);
				$("#exportContractForm").submit();
			});
			
			
			//关闭订单详情
			$("#selectOrderDetailCloseButton").click(function() {
				$("#selectOrderDetail").css("display", "none");
				$("#selectProductOrderDetailBackground").css("display", "none");
			});
			
			//作废	
			$("#disableOrder").click(function() {
				var charger = $("#disableCharger").select2("val");
				$(this).addClass("disabled");
				var id = "", idArr, ids = "";
				//获得所有选择的订单编号
				$("input[name^='prorder_']:checked").each(function() {
					id = $(this).attr("name");
					idArr = id.split("_");
					ids += idArr[1] + ",";
				});
				
				ids = ids.substring(0, ids.length - 1);
				//如果未选择
				if(ids == null || ids.length <= 0) {
					$("#disableOrder").removeClass("disabled");
					error("请选择一个订单");
					return;
				}
				
				//后台提交
				$.ajax({
					type		: "post",
					url			: "yueyogaAdmin/disableOrder.jhtml",
					async		: false,
					data		: {"ids" : ids, "charger": charger},
					success		: function(res) {
						var response = eval("(" + res + ")");
						if(response.success) {
							var d = alert(response.msg);
							$("#disableOrder").removeClass("disabled");
							$("#disableOrderPanel").css("block", "none");
							setTimeout(function() {
								d.close().remove();
								window.location.reload();
							}, 1000);
						} else {
							$("#disableOrder").removeClass("disabled");
							error(response.msg);
						}
					}
				});
			});
		};
		
		
		function toggleDiv() {
			var flag = $("#buyProductsDetails").css("display");
			if (flag == "none") {
				$("#buyProductsDetails").css("display", "block");
				
				var realcost = $("#selectProduct #realCost").val();

				$("#buyProductsDetails #amounts").val(realcost);
				//开始日期默认当天
				var today = new Date();
				var y = today.getFullYear();
				var m = today.getMonth()+1;
				var d = today.getDate();
				m = m<10?"0"+m:m;
				d = d<10?"0"+d:d;
				
				$("#buyProductsDetails #qzBeginDate").val(y+"-"+m+"-"+d);
				
			} else if (flag == "block") {
				$("#buyProductsDetails").css("display", "none");
			}
		}
		
		function toggleTimeDiv(){
			var flag = $("#buyProductTime").css("display");
			if (flag == "none") {
				$("#buyProductTime").css("display", "block");
			} else if (flag == "block") {
				$("#buyProductTime").css("display", "none");
			}
			var title = $("#buyProductTime h3").text();
			if(title=='产品续费'){
				$("#buyProductTime h3").text("产品有效时间");
			}
			$("#divFzr").hide();
		}
		
		function toggleRefundDiv(){
			var flag = $("#refundProducts").css("display");
			if (flag == "none") {
				$("#refundProducts").css("display", "block");
			} else if (flag == "block") {
				$("#refundProducts").css("display", "none");
			}
			/* $("#refundProducts").slideToggle("fast"); */
		}
		
		function toggleClearOrderDiv() {
			/* $("#clearOrderDiscount").slideToggle("fast"); */
			var flag = $("#clearOrderDiscount").css("display");
			if (flag == "none") {
				$("#clearOrderDiscount").css("display", "block");
			} else if (flag == "block") {
				$("#clearOrderDiscount").css("display", "none");
			}
		}
		
		function showBuyProducts() {
			var arr = $("input[name^='chk_proname_']:checked");

			if (arr.length < 1) {
				error("请选择一件产品进行购买!");
				return;
			} else if (arr.length > 1) {
				error("只能选择一件产品进行购买!");
				arr.splice(0,arr.length); 
				return;
			} else {
				toggleDiv();
			}
		}
		
		//浮点数加法运算  
		function FloatAdd(arg1,arg2){  
			var r1,r2,m;  
			try{
				r1 = arg1.toString().split(".")[1].length;
			} catch(e) {
				r1 = 0;
			}  
			try{
				r2 = arg2.toString().split(".")[1].length;
			} catch(e) {
				r2 = 0;
			}  
			m = Math.pow(10, Math.max(r1, r2));
			return (arg1*m+arg2*m)/m;
		}
		
		//购买产品
		function buyProducts() {
			$("#btn_buy_product").addClass("disabled");
			var earnest = $("#earnest").val();
			var buyType = $("#buyType").val();
			var beginDate = $("#qzBeginDate").val();
			var endDate = $("#qzEndDate").val();
			var amounts = $("#amounts").val();
			var payType = $("#payType").select2("val");
			if (buyType == '定金' && !earnest) {
				$("#buyProductsDetails").hide();
				var d = alert("定金不能为空!");
				setTimeout(function() {
					d.close().remove();
					$("#buyProductsDetails").show();
				}, 2000);
				return;
			}
			
			var arr = new Array();
			var id = "";
			//获得选中的产品Id
			$("input[name^='chk_proname_']:checked").each(function() {
				id = $(this).attr("name");
				id = id.substring(12, id.length);
				arr.push(id);
			});
			
			//折扣不能大于总价格
			var prices = 0;
			$("input[name^='chk_proname_']:checked").each(function() {
				var id = $(this).val();
				var price = $("#tdp_" + id).text();
				if(isNaN(price)) {//parseFloat(price) != price
					$("#buyProductsDetails").hide();
					var d = alert("价格格式不正确！");
					setTimeout(function() {
						d.close().remove();
						$("#buyProductsDetails").show();
					}, 2000);
					return false;
				}
				
				prices = FloatAdd(prices, price);
			});
			
			var ids = arr.join(",");
			if (ids.length > 0) {
				var memberId = $("#hidMemberId").val();
				var sellerId = $("#input").val();
				var discount = $("#discount").val();
				if(prices < discount) {
					$("#buyProductsDetails").hide();
					var d = alert("折扣大于总价格！");
					setTimeout(function() {
						d.close().remove();
						$("#buyProductsDetails").show();
					}, 2000);
					return;
				}
				
				$.ajax({
					type		: "post",
					url			: "yueyogaAdmin/buyProduct.jhtml",
					async		: false,
					data		: {"memberId" : memberId, "productId" : ids, "sellerId" : sellerId, "buyType" : buyType, "earnest" : earnest, "discount" : discount, "beginDate":beginDate, "endDate":endDate, "zongjine":amounts, "payType": payType},
					success		: function(result) {
						toggleDiv();
						var data = eval("("+result+")");
						if (data.success=='true') {
							window.location.href = "yueyogaAdmin/toMemberProduct.jhtml?memberId="+memberId;
						} else {
							$("#buyProductsDetails").hide();
							error(data.msg);
						}
					},
					error		: function() {
						alert("购买错误！");
					}
				});
			} else {
				$("#buyProductsDetails").hide();
				var d = alert("请选择产品!");
				setTimeout(function() {
					d.close().remove();
					$("#buyProductsDetails").show();
				}, 2000);
				return;
			}
		}
		
		//--指定时间
		function grantProductTime(){
			var tit = $("#buyProductTime h3").text();
			
			
			$("#proremaining_chkall").prop("checked",false);
			$("input[name='proremaining_item']").prop("checked",false);
			
			
			var tempArray = new Array();
			var proBeginTime = $("input[name='proBeginTime']").val();
			var proEndTime 	 = $("input[name='proEndTime']").val();
			
			var proRemainIds = $("#checkedProductRemainingIds").val();
			
			var memberId = $("#hidMemberId").val();
			
			if(proRemainIds){
				tempArray = proRemainIds.split(',');
			}
			var url = "yueyogaAdmin/updateProRemainingTime.jhtml";
			var xfurl = "yueyogaAdmin/renewalsProducts.jhtml";
			if(tit=='产品有效时间'){
				$.post(url,
						{
						proRemainIds:proRemainIds,
						proBeginTime:proBeginTime,
						proEndTime:proEndTime
						},
						function(msg){
							if(msg=='gts'){
								$.each(tempArray,function(){
									$("#ks_"+this).text(proBeginTime);
									$("#js_"+this).text(proEndTime);
									$("#kssy_"+this).text(proBeginTime);
									$("#jssy_"+this).text(proEndTime);
								});
							}else{
								error("指定时间失败!");
							}
						});
			}else{
				var sellerId = $("#selFzrs").val();
				if(!sellerId){
					toggleTimeDiv();
					var d = alert("请选择负责人!");
					setTimeout(function() {
						d.close().remove();
					}, 1000);
					return;
				}
				var productIds = '';
				$.each(tempArray,function(){
					productIds+=$("#pro_"+this).text()+",";
				});
				if(productIds){
					productIds = productIds.substring(0, productIds.length -1);
				}
				$.post(xfurl,{
					productIds:productIds,
					memberId:memberId,
					sellerId:sellerId,
					proBeginTime:proBeginTime,
					proEndTime:proEndTime},
					function(data){
						var resp = eval('('+data+')');
						if(resp.success){
							window.location.reload();
						}else{
							error(resp.msg);
						}
					});
			}
			toggleTimeDiv();
		}
		
		//结清
		$("#clearOrderDiscountBuyButton").click(function() {
			$(this).addClass("disabled");
			var chaId = $("#clearCharger").select2("val");
			var id = "", idArr, ids = "";
			//获得所有选择的订单编号
			$("input[name^='prorder_']:checked").each(function() {
				id = $(this).attr("name");
				idArr = id.split("_");
				ids += idArr[1] + ",";
			});
			ids = ids.substring(0, ids.length - 1);
			
			var discount = $("#clearOrderDiscountPrice").val();
			if(parseFloat(discount) != discount) {
				alert("请输入整数或小数！");
				$(this).removeClass("disabled");
				return;
			}
			
			if(discount < 0) {
				alert("折扣不能小于零！");
				$(this).removeClass("disabled");
				return;
			}
			
			//后台提交
			$.ajax({
				type		: "post",
				url			: "yueyogaAdmin/clearOrder.jhtml",
				async		: false,
				data		: {"ids" : ids, "discount" : discount, "responseId": chaId},
				success		: function(res) {
					toggleClearOrderDiv();
					
					var response = eval("(" + res + ")");
					if(response.success) {
						window.location.reload();
					} else {
						error(response.msg);
					}
				}
			});
			$(this).removeClass("disabled");
		});
		
		$("#clearOrderDiscountCancelButton").click(function() {
			toggleClearOrderDiv();
		});
	</script>
</body>
</html>
